import {
  DeviceValueExTaskFormData,
  DeviceValueExTaskPageResult,
  DeviceValueExTaskQueryParam,
  DeviceValueExTaskRequestVO,
} from './types';
import request from '@/utils/request';
import {AxiosPromise} from 'axios';

/**
 * 获取实体分页列表
 *
 * @taskParam queryParams
 */
export function listEntityPages(queryParams: DeviceValueExTaskQueryParam): AxiosPromise<DeviceValueExTaskPageResult> {
  return request({
    url: '/kernel/manager/device/value/ex/task/page',
    method: 'post',
    data: {
      taskName: queryParams.taskName,
      pageNum: queryParams.pageNum,
      pageSize: queryParams.pageSize
    },
  });
}

/**
 * 获取实体详情
 *
 * @taskParam id
 */
export function getEntity(id: number): AxiosPromise<DeviceValueExTaskFormData> {
  return request({
    url: '/kernel/manager/device/value/ex/task/entity',
    method: 'get',
    params: {id: id}
  });
}

export function updateScript(id: number, script: string) {
  return request({
    url: '/kernel/manager/device/value/ex/task/entity/script',
    method: 'put',
    data: {
      id: id,
      script: script,
    }
  });
}

/**
 * 添加实体
 *
 * @taskParam data
 */
export function createEntity(data: DeviceValueExTaskRequestVO) {
  return request({
    url: '/kernel/manager/device/value/ex/task/entity',
    method: 'post',
    data: data,
  });
}

/**
 * 修改实体
 *
 * @taskParam data
 */
export function updateEntity(data: DeviceValueExTaskRequestVO) {
  return request({
    url: '/kernel/manager/device/value/ex/task/entity',
    method: 'put',
    data: {
      id: data.id,
      taskName: data.taskName,
      taskParam: data.taskParam,
    },
  });
}

/**
 * 删除实体列表
 *
 * @taskParam ids
 */
export function deleteEntity(ids: string) {
  return request({
    url: '/kernel/manager/device/value/ex/task/entities',
    method: 'delete',
    params: {ids: ids},
  });
}
